package com.scaffold.controller.impl;

import com.scaffold.controller.UserApi;
import com.scaffold.converter.UserConverter;
import com.scaffold.model.domain.UserDO;
import com.scaffold.model.vo.UserPostVO;
import com.scaffold.model.vo.UserPutVO;
import com.scaffold.model.vo.UserVO;
import com.scaffold.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Da Shuai
 * @since 2021-08-21 16:02:23
 */
@RestController
@RequiredArgsConstructor
public class UserController implements UserApi {

    private final UserService userService;

    @Override
    public UserVO save(UserPostVO postVO) {
        UserDO userPost = UserConverter.toDO(postVO);
        UserDO user = userService.save(userPost);
        return UserConverter.toVO(user);
    }

    @Override
    public void delete(Long id) {
        userService.deleteById(id);
    }

    @Override
    public UserVO update(UserPutVO putVO) {
        UserDO userPut = UserConverter.toDO(putVO);
        UserDO user = userService.update(userPut);
        return UserConverter.toVO(user);
    }

    @Override
    public UserVO get(Long id) {
        UserDO user = userService.getById(id);
        return UserConverter.toVO(user);
    }

    @Override
    public List<UserVO> get() {
        return null;
    }
}
